<template>
	<view>
		<view class="formGroup">
		<view class="formItem">
			<view class="formLabel">车间名称<text class="red">*</text></view>
			<input v-model="info.chejianname" class="wq-ipt">
					
			</input>
			<view class="formLabel">联系方式<text class="red">*</text></view>
			<input v-model="info.phone" class="wq-ipt">
		
			</input>
			<view class="formLabel">姓名<text class="red">*</text></view>
			<input v-model="info.name" class="wq-ipt">
					
			</input>
			<view class="formLabel">登录密码(修改时可传空，即不修改密码)<text class="red">*</text></view>
			<input v-model="info.password" class="wq-ipt">
					
			</input>
			<view class="xidi">
				<button class="wq-btn" @tap="save">保存</button>
			</view>
			
		</view>
		</view>
	</view>
</template>

<script>
	import api from '@/api.js'
	export default {
		data() {
			return {
				info:{
					name:"",
					password:"",
					phone:"",
					chejianname:""
				}
			}
		},
		onLoad(e){
			let id=e.id;
			if(id){
				api.doRequest('get','my/getPersonInfo',{id:id}).then(res=>{
					this.info=res.data.data;
					this.info.password='';
				})
			}
			
		},
		onBackPress(options) {
					let pages = getCurrentPages() // 上一个页面实例对象   
					let beforePage = pages[pages.length - 2]
					beforePage.$vm.reloadCurrentList(); 
		},
		onUnload(){
			let pages = getCurrentPages() // 上一个页面实例对象
			let beforePage = pages[pages.length - 2]
			beforePage.$vm.reloadCurrentList();
		},
		methods: {
			save(){
				if(this.info.name==''){
					uni.showToast({
						title:"请填写姓名",
						icon:"none"
					})
				}
				else if(this.info.password=="" && !this.info.id){
					uni.showToast({
						title:"请填写登录密码",
						icon:"none"
					})
				}else if(this.info.chejianname==""){
					uni.showToast({
						title:"请填写车间名称",
						icon:"none"
					})
				}
				else if(this.info.phone=="" ){
					uni.showToast({
						title:"请填写手机号",
						icon:"none"
					})
				}else{
					let data=this.info;
					api.doRequest('post','my/personSave',data).then(res=>{
						if(res.data.code==200){
							uni.showToast({
								title:"保存成功",
								icon:"none"
							})
							setTimeout(function(){
								uni.navigateBack();
							},1000);
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:"none"
							})
						}
					})
				}
				
			}
		}
	}
</script>

<style>
.formLabel{margin:20upx;}
.red{color:#f00;}
.wq-ipt{border:1upx solid #ccc;width:670upx;padding:20upx;margin:20upx;border-radius:20upx;}
</style>
